/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.database.tables;

import aiaudio.database.Family;
import java.util.Map.Entry;
import java.util.NavigableMap;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

/**
 *
 * @author nastya
 */
public class NeighbourUserToGroupTable extends TableStructure {

    private final static Family GROUPS = new Family("g");

    public static void addGroupForUser(Put put, int groupNumber, double similarity) {
        put.add(GROUPS.getNameAsBytes(), Bytes.toBytes(groupNumber), Bytes.toBytes(similarity));
    }

    public static NavigableMap<byte[], byte[]> getGroups(Result value) {
        return value.getFamilyMap(GROUPS.getNameAsBytes());
    }

    public static double getTypedValue(Entry<byte[], byte[]> entry) {
        return Bytes.toDouble(entry.getValue());
    }

    @Override
    public Family[] getAllFamilies() {
        return new Family[]{GROUPS};
    }
}
